#include "gtest/gtest.h"

#include "BlockManager.h"


using namespace streamdb;

TEST(BlockManagerTest, use){
    BlockManager * bm = new BlockManager;
    std::string stream = "block-test.stream";
    ASSERT_TRUE(bm->regStream(stream).isOk());

    ASSERT_EQ(1, bm->getStreamCount());

    
    {
        for(int i = 0 ; i < 64; ++i){
            bm->append(stream, "hello");
        }

        ASSERT_EQ(5, bm->getStreamBlockCount(stream));
    }
    
    std::cout << "hello...............next append" << std::endl;

    {
        std::string longstring(64*16, 'a');
        ASSERT_TRUE(bm->append(stream, longstring.c_str()).isOk());

        ASSERT_EQ(5 + 16, bm->getStreamBlockCount(stream));
    }

    ASSERT_TRUE(bm->flush().isOk());

    
    ASSERT_TRUE(bm->unregStream(stream).isOk());
    delete bm;
}
